package com.jwgf.Half485.modbusthreadpool;

import com.jwgf.Half485.CommandQueueAction;

public class ModbusAction implements CommandQueueAction {
    @Override
    public CMD_QUEUE_ACTION act(Object data) {
        ModbusData modbusData = (ModbusData) data;
        byte cmdType = ModbusUtils.checkCmdType(modbusData.send);
        if (cmdType == ModbusUtils.WRITE_HOLDING_REGISTER || cmdType == ModbusUtils.WRITE_COIL) {
            if (modbusData.isDone) {
                PLCData.getInstance().writeSucceed(modbusData);
            } else {
                PLCData.getInstance().writeFailed(modbusData);
            }
            return CMD_QUEUE_ACTION.NEXT;
        } else {
            if (modbusData.isDone) {
                PLCData.getInstance().readSucceed(modbusData);
                return CMD_QUEUE_ACTION.NEXT;
            } else {
                PLCData.getInstance().readFailed(modbusData);
                return CMD_QUEUE_ACTION.REPEAT;
            }

        }
    }
}
